package com.dadie.dorm.service.impl;




import com.dadie.dorm.dao.IStudentDao;
import com.dadie.dorm.dao.impl.StudentDaoImpl;
import com.dadie.dorm.pojo.Student;
import com.dadie.dorm.pojo.query.StudentQuery;
import com.dadie.dorm.service.IStudentService;
import com.dadie.dorm.util.LayUITableResult;

import java.util.List;

public class StudentServiceImpl implements IStudentService {
    public IStudentDao studentDao=new StudentDaoImpl();
    @Override
    public LayUITableResult selectByPage(StudentQuery studentQuery) {
        List<Student> list=studentDao.selectByPage(studentQuery);
        Integer totalCount=studentDao.selectTotalCount(studentQuery);
        return LayUITableResult.ok(totalCount,list);
    }

    @Override
    public boolean deleteById(int id) {
        int count=studentDao.deleteById(id);
        return count==1 ? true: false;
    }

    @Override
    public boolean add(Student student) {
        int count=studentDao.add(student );
        return count==1 ? true: false;
    }



    @Override
    public boolean deleteAll(String[] ids) {
        // delete from student where id in();
        int count = 0;
        for (String id : ids) {
            count += studentDao.deleteById(Integer.parseInt(id));
        }
        return count == ids.length ? true : false;
    }

    @Override
    public boolean update(Student student) {
        int count=studentDao.update(student);
        return count==1 ? true: false;
    }

    @Override
    public Student selectById(int id) {
        return studentDao.selectById(id);

    }

}
